﻿using Bll;
using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


namespace Myproject.BSM.Ashx.PcChannel
{
    /// <summary>
    /// AgencyClassAjax 的摘要说明
    /// </summary>
    public class AgencyClassAjax : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (!string.IsNullOrEmpty(cookieHelp.AdminId))
            {
                if (new AdminBLL().ExistsByAdminName(cookieHelp.AdminName) && new AdminBLL().ExistsByAdminId(cookieHelp.AdminId))
                {

                    string dos = context.Request.Params["dos"];
                    string id;
                    #region swith do
                    switch (dos)
                    {
                        case "delete":
                            id = context.Request.QueryString["id"];
                            if (new AgencyClassBLL().Delete(int.Parse(id)))
                            {
                                context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "删除成功！", "pc_channel_agencyClassList", "", "", false, "", ""));
                            }
                            else
                            {
                                context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "删除失败！", "pc_channel_agencyClassList", "", "", false, "", ""));
                            }
                            break;

                        case "edit":
                            id = context.Request.Params["pc_Channel_AgencyClassEdit_AgencyClassId"].Trim();
                            string name = context.Request.Params["pc_Channel_AgencyClassEdit_AgencyClassname"].Trim();
                            string goodsid = context.Request.Params["pc_Channel_AgencyClassEdit_goodsID"].Trim();
                            string no = context.Request.Params["pc_Channel_AgencyClassEdit_AgencyClassNo"].Trim();
                            string rank = context.Request.Params["pc_Channel_AgencyClassEdit_AgencyClassrank"].Trim();
                            if (id == "0")
                            {
                                AgencyClassModel model = new AgencyClassModel();
                                model.AgencyClassName = name;
                                model.AgencyClassNo = no;
                                model.GoodsID = Int32.Parse(goodsid);
                                model.Rank = Int32.Parse(rank);

                                if (new AgencyClassBLL().Add(model) > 0)
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "新增代理类别成功！", "pc_channel_agencyClassList", "", "", true, "", ""));
                                }
                                else
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "新增代理类别失败！", "pc_channel_agencyClassList", "", "", true, "", ""));
                                }
                            }
                            else
                            {
                                AgencyClassModel model = new AgencyClassBLL().GetModel(Int32.Parse(id));
                                model.AgencyClassName = name;
                                model.AgencyClassNo = no;
                                model.GoodsID = Int32.Parse(goodsid);
                                model.Rank = Int32.Parse(rank);
                                if (new AgencyClassBLL().Update(model))
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改代理类别成功！", "pc_channel_agencyClassList", "", "", true, "", ""));
                                }
                                else
                                {
                                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改代理类别失败！", "pc_channel_agencyClassList", "", "", true, "", ""));
                                }
                            }
                            break;
                    }
                    #endregion
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(301, "登陆超时！", "", "", "", false, "/bsm/logFrom.aspx", "登陆超时！"));
                }
            }
            else
            {
                context.Response.Write(ReturnJsonHelp.BJUIajaxJson(301, "登陆超时！", "", "", "", false, "/bsm/logFrom.aspx", "登陆超时！"));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}